package org.hxyjs.service.impl;

import org.hxyjs.dao.OthersDao;
import org.hxyjs.dto.DTO;
import org.hxyjs.dto.MessageEnum;
import org.hxyjs.entity.Others;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.OthersService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service("OthersService")
public class OthersServiceImpl implements OthersService {
    @Resource
    OthersDao othersDao;
    @Override
    public DTO<Others> getAllOtherss()  throws Exception{
        List<Others> otherss = othersDao.getAllOtherss();
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(otherss).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<Others>(messageEnum.getCode(),messageEnum.getMessage(),otherss);
    }

    @Override
    public DTO<Others> deleteOthersByOno(String ono)  throws Exception{
        Integer result = othersDao.deleteOthersByOno(ono);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  =result> 0?MessageEnum.DELETEADMINSUCCESS:MessageEnum.DELETEADMINFAIL;
        return new DTO<Others>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Others> updateOthersByOno(Others others) throws Exception {
        Integer result = othersDao.updateOthersByOno(others);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  =result> 0?MessageEnum.UPDATEADMINSUCCESS:MessageEnum.UPDATEADMINFAIL;
        return new DTO<Others>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Others> addOthersByOno(Others others) throws Exception {
        Integer result = othersDao.addOthersByOno(others);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  =result> 0?MessageEnum.ADDADMINSUCCESS:MessageEnum.ADDADMINFAIL;
        return new DTO<Others>(messageEnum.getCode(),messageEnum.getMessage());
    }

    /**
     * 学生选课成功 学生成绩加1分，从选课信息中可以获得学生的学号就能查询出学生原来的成绩
     * @param
     * @return
     * @throws Exception
     */


    @Override
    public DTO<Others> getOthersByOno(String ono)  throws Exception{
        Others otherss = othersDao.getOthersByOno(ono);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(otherss).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<Others>(messageEnum.getCode(),messageEnum.getMessage(),otherss);
    }

    @Override
    public DTO<Others> getOthersByPage(PageInfo pageInfo) throws Exception {
        List<Others> otherss = othersDao.getOthersByPage(pageInfo);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(otherss).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<Others>(messageEnum.getCode(),messageEnum.getMessage(),otherss,pageInfo);
    }
}
